// pages/activeDetail/activeDetail.js
var app = getApp()
var utils = require('../../utils/util.js');
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bg: { img: '/images/pic/h_1.png' },
    active: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    var sucFunc = function (that, res) {
      that.setData({
        active: res.data.res,
        status:res.data.status,
        num:res.data.count,
        imgPath: app.d.imgPath
      })
      wx.hideLoading();
      WxParse.wxParse('article', 'html', res.data.res.content, that, 5)
    }
    var data = { openid: app.d.openid, id: options.id }
    utils.wxRequest(that, app.d.path, "Activity/detail", data, sucFunc);
  },
  bm:function(){
    var that = this;
    if (that.data.status < 1 && that.data.active.count-that.data.num > 0){
      wx.showLoading({
        title: '加载中',
      })
      var sucFunc = function (that, res) {
        if(res.data == 200){
          wx.showModal({
            title: '提示',
            content: '报名成功，再逛逛吧！',
            success(res) {
              wx.redirectTo({
                url: "/pages/about/about"
              })
            }
          })
        }else{
          wx.showModal({
            title: '提示',
            content: '报名失败，稍后重试！',
            success(res) {
              return false
            }
          })
        }
        
        wx.hideLoading();
      }
      var data = { openid: app.d.openid, id: that.data.active.id }
      utils.wxRequest(that, app.d.path, "Activity/bm", data, sucFunc);
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})